<template>
	<view class="body">
		
		<!-- 分类导航栏 -->
		<swiper-tab-head 
		:tabBars="tabBars" 
		:tabIndex="tabIndex" 
		@tabTap="tabTap"
		scrollStyle="border-bottom:0;"
		scrollItemStyle="width:33.333%;"
		/>
		
		<!-- 好友列表 -->
		<view class="uni-tab-bar">
			<swiper 
			class="swiper-box" 
			:style="{ 'height': swiperheight + 'px' }" 
			:current="tabIndex"
			@change="tabChange"
			>
				<swiper-item v-for="(items,index) in newslist" :key="index">
					<scroll-view scroll-y class="list">
						<block v-for="(item,key) in items.list" :key="key">
							<user-list :item="item" :index="key" />
						</block>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import swiperTabHead from '../../components/index/swiper-tab-head.vue';
	import userList from "../../components/user-list/user-list.vue";
	export default {
		data() {
			return {
				swiperheight: 500,
				tabIndex: 0,
				tabBars: [{
				    name: '互关',
					num:30,
				    id: 'huguan'
				}, {
				    name: '关注',
					num:45,
				    id: 'guanzhu'
				}, {
				    name: '粉丝',
					num:8,
				    id: 'fensi'
				}],
				newslist:[
					{
						list:[
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							}
						]
					},
					{
						list:[
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							}
						]
					},
					{
						list:[
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:20,
								sex:0,
								isguanzhu:true
							},
							{
								userpic:"../../static/demo/userpic/11.jpg",
								username:"昵称",
								age:21,
								sex:1,
								isguanzhu:false
							}
						]
					}
				]
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success(res) {
					this.swiperheight = res.windowHeight - uni.upx2px(100);
				}
			})
		},
		methods: {
			// 监听原生按钮点击事件
			onNavigationBarButtonTap(e) {
				// e.index 代表按钮的索引
				// 这里只有一个按钮，所以该按钮索引为0
				if(e.index == 0){
					uni.navigateBack({
						delta: 1 //返回一步
					})
				}
			},
			// 监听搜索框文本变化
			onNavigationBarSearchInputChanged(e){
				console.log('监听搜索框文本变化:',e.text);
			},
			//监听点击搜索按钮事件(点击手机键盘上搜索时触发)
			onNavigationBarSearchInputConfirmed(e){
				console.log('监听点击搜索按钮事件:',e.text);
			},
			//tabbar点击事件
			tabTap(index){
				this.tabIndex = index;
			},
			//滑动事件
			tabChange(e){
				this.tabIndex = e.detail.current;
			}
		},
		components:{
			swiperTabHead,
			userList
		}
	}
</script>

<style scoped>
.body{
	padding: 0 20upx;
}
</style>
